package exam;

import java.util.Scanner;

/**
 * @author DengYuan2
 * @create 2021-03-26 20:41
 */
public class Test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入月份和日子");
        String monthAndDay = scanner.nextLine();
        System.out.println("请输入字符串");
        String str=scanner.nextLine();
        Test2 test2 = new Test2();
        String[] md = monthAndDay.split(" ");
        String result = test2.getResult(Integer.parseInt(md[0]), Integer.parseInt(md[1]), str);
        System.out.println("结果为：");
        System.out.println(result);

    }

    public  char[] group1="ABCDEFGHI".toCharArray();
    public char[] group2="JKLMNOPQR".toCharArray();
    public char[] group3="STUVWXYZ ".toCharArray();

    public String getResult(int month,int day,String str){
        StringBuilder ret = new StringBuilder();
        int group =(month-1)%3;
        char[] g1,g2,g3;
        if (group==0){
            g1=group1;
            g2=group2;
            g3=group3;
        }else if (group==1){
            g1=group2;
            g2=group3;
            g3=group1;
        }else {
            g1=group3;
            g2=group1;
            g3=group2;
        }
        char[][] all = {g1,g2,g3};
        for (int i = 0; i < str.length(); i++) {
            int[] groupAndCount = getGroupAndCount(all, str.charAt(i));
            int off=(day-1)%9;
            int res=groupAndCount[1]>off?groupAndCount[1]-off:groupAndCount[1]+9-off;
            ret.append(groupAndCount[0]+""+res).append(" ");

        }
        return ret.toString();

    }

    public int[] getGroupAndCount(char[][] all,char key){
        int[] res = new int[2];
        for (int i = 0; i < all.length; i++) {
            for (int j = 0; j < all[i].length; j++) {
                if (all[i][j]==key){
                    res[0]=i+1;
                    res[1]=j+1;
                    return res;
                }
            }
        }
        return res;
    }

}
